﻿/**
 * 配置参数文件
 */
(function () {
  var URL = window.PuXu_HOME_URL || getUEBasePath();
  /**
 * 配置项主体。注意，此处所有涉及到路径的配置别遗漏URL变量。
 */
  window.PuXu_CONFIG = {
    //为编辑器实例添加一个路径，这个不能被注释
    PuXu_HOME_URL: URL,

    // 服务器统一请求接口路径
    //serverUrl: URL + "php/controller.php",
    serverUrl: URL + "net/controller.ashx",

    //工具栏上的所有的功能按钮和下拉框，可以在new编辑器的实例时选择自己需要的重新定义
    toolbars: [
      ['source', 'undo', 'redo'],
      ['copy', 'paste', 'cut'],
      ['inserttextblock'],
      ['insertimage'],
      ['inserttable', 'insertshape'],
      ['backcolor', 'bordercolor'],
      ['hierarchy'],
      ['fontfamily'],
      ['fontsize'],
      ['bold', 'italic', 'underline', 'strikethrough'],
      'line',
      ['forecolor', 'addfontsize', 'reducefontsize'],
      'line',
      ['alignment', 'textdirection'],
      'line',
      ['wordspacing', 'lineheight', 'indent'],
      'line',
      ['justifyleft', 'justifycenter', 'justifyright'],
      'line',
      ['justifyjustify', 'justifydistribute'],
      'line',
      ['verticaltop', 'verticalcenter', 'verticaldown']
    ],

    toolfoot: ['Editiframeleft', 'Editiframeright']
  };

  function getUEBasePath(docUrl, confUrl) { return getBasePath(docUrl || self.document.URL || self.location.href, confUrl || getConfigFilePath()); }

  function getConfigFilePath() { var configPath = document.getElementsByTagName("script"); return configPath[configPath.length - 1].src; }

  function getBasePath(docUrl, confUrl) {
    var basePath = confUrl;
    if (/^(\/|\\\\)/.test(confUrl)) {
      basePath = /^.+?\w(\/|\\\\)/.exec(docUrl)[0] + confUrl.replace(/^(\/|\\\\)/, "");
    } else if (!/^[a-z]+:/i.test(confUrl)) {
      docUrl = docUrl.split("#")[0].split("?")[0].replace(/[^\\\/]+$/, "");
      basePath = docUrl + "" + confUrl;
    }
    return optimizationPath(basePath);
  }

  function optimizationPath(path) {
    var protocol = /^[a-z]+:\/\//.exec(path)[0], tmp = null, res = [];
    path = path.replace(protocol, "").split("?")[0].split("#")[0];
    path = path.replace(/\\/g, "/").split(/\//);
    path[path.length - 1] = "";
    while (path.length) { if ((tmp = path.shift()) === "..") { res.pop(); } else if (tmp !== ".") { res.push(tmp); } }
    return protocol + res.join("/");
  }

  window.puxu = { getUEBasePath: getUEBasePath };
  window.puxuBox = {};
})();